package com.service;

import com.MybatisUtil.MybatisUtil;
import com.bean.Users;
import com.dao.UsersMapper;

public class UsersService {


    public static void updatepwd(int id, String newpwd ,Users loginUsers ) {

        UsersMapper dao = MybatisUtil.getMapper(UsersMapper.class);
        Users users =new Users();
        users.setId(id);
        users.setPwd(newpwd);
        dao.updatePartial(users);
        //修改会话中的密码
        loginUsers.setPwd(newpwd);
        MybatisUtil.commit();
    }

    public Users login(String account, String pwd){
        UsersMapper dao = MybatisUtil.getMapper(UsersMapper.class);
        Users user = dao.findByName(account);
        if(user!=null && user.getPwd().equals(pwd)){
            System.out.println("TEST0");
            return user;
        }
        return null;
    }
    public void reg(Users user){
        UsersMapper dao = MybatisUtil.getMapper(UsersMapper.class);
        dao.add(user);
        MybatisUtil.commit();
    }
}
